package com.ben.notebook.controller;

import com.ben.notebook.infrastructure.util.BusinessRuntimeException;
import com.ben.notebook.infrastructure.util.ErrorMsgEnum;
import com.ben.notebook.infrastructure.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * springmvc异常处理类
 * todo：使用log
 * @date 2020-12-12
 */
@RestControllerAdvice
public class BusinessExceptionHandler {

    @ExceptionHandler(BusinessRuntimeException.class)
    public JsonResult handleBusinessException(BusinessRuntimeException e){

        return JsonResult.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public JsonResult handleException(Exception e){

        return JsonResult.error(ErrorMsgEnum.UNKNOWN_ERROR);
    }
}
